// GameListView.cpp : implementation file
//

#include "stdafx.h"
#include "resource.h"
#include "GameListView.h"
#include ".\gamelistview.h"


// CGameListView

IMPLEMENT_DYNCREATE(CGameListView, CWnd)


CGameListView::~CGameListView()
{
}

BEGIN_MESSAGE_MAP(CGameListView, CWnd)
	ON_WM_SIZE()
	ON_NOTIFY(HTMLLIST_SELECTIONCHANGED,123,OnHTMLList_SelectionChanged)
	ON_NOTIFY(HTMLLIST_LBUTTONDOWN,123,OnHTMLList_LButtonDown)
	ON_NOTIFY(HTMLLIST_LBUTTONDBLCLICK,123,OnHTMLList_LButtonDBLClick)
	ON_NOTIFY(HTMLLIST_RBUTTONDOWN,123,OnHTMLList_RButtonDown)
	ON_NOTIFY(HTMLLIST_ITEMCHECKED,123,OnHTMLList_CheckStateChanged)

	ON_WM_ACTIVATE()
	ON_MESSAGE(WM_EVENT_WRAPPER_FOR_THREAD_SAFE,HandleModelEvent)

END_MESSAGE_MAP()


// CGameListView drawing

void CGameListView::OnDraw(CDC* pDC)
{

	// TODO: add draw code here
}


// CGameListView diagnostics

#ifdef _DEBUG
void CGameListView::AssertValid() const
{
	CWnd::AssertValid();
}

void CGameListView::Dump(CDumpContext& dc) const
{
	CWnd::Dump(dc);
}
#endif //_DEBUG


// CGameListView message handlers

void CGameListView::OnInitialUpdate()
{
	



	m_ImageList.Create(16,16,ILC_COLOR24|ILC_MASK,4,4);
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON_TEST));
	m_ImageList.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));
	CRect rc;
	this->GetParent()->GetWindowRect(&rc);
	m_list.Create(this,CRect(0,0,rc.Width()-2,rc.Height()-2),123,WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_TABSTOP);

	m_list.SetImageList(&m_ImageList);



	m_list.SetExtendedStyle(HTMLLIST_STYLE_GRIDLINES|HTMLLIST_STYLE_CHECKBOX|HTMLLIST_STYLE_IMAGES);

//	m_list.InsertItem("NEW GAME",0,SINGLE_LINE_TEXT,40);
 /*
	m_list.InsertItem("This is a test string, Height is AUTO (according to text)",0,NORMAL_TEXT);

	m_list.InsertItem("This is a test string, Single Line style and Specified Height(40px)",0,SINGLE_LINE_TEXT,40);

	m_list.InsertItem("This string is too long and will not be wraped, instead it will end in ellipses, This is a test string, ",0,SINGLE_LINE_TEXT,30);

	for(int i = 0;i < 10;i++)
	{
		CString str;
		str.Format("<font color=#ff0000>This is Red Text</font>, <b>This is Bold Text</b>, \
This harmless looking string will actually <u><b>wrap</b></u> to the next line , <br>A BR tag was used to move this line to the next line (%d)",i);
		m_list.InsertItem(str,0,HTML_TEXT);//NORMAL_TEXT);
	}
	

	m_list.InsertItem("This is a test",1,NORMAL_TEXT);
  */


	m_list.ShowWindow(SW_SHOW);

	// TODO: Add your specialized code here and/or call the base class
}
void CGameListView::OnHTMLList_LButtonDown(NMHDR* pNMHDR, LRESULT*)
{
	//MessageBox("LButtonDown");
}

void CGameListView::OnHTMLList_LButtonDBLClick(NMHDR* pNMHDR, LRESULT*)
{
	MessageBox("Double Clicked");
}

void CGameListView::OnHTMLList_RButtonDown(NMHDR* pNMHDR, LRESULT*)
{
	MessageBox("Right Button Clicked");
}
void CGameListView::OnHTMLList_CheckStateChanged(NMHDR* pNMHDR, LRESULT*)
{
	NM_HTMLLISTCTRL *pListNMHDr = (NM_HTMLLISTCTRL*) pNMHDR;


	if(pListNMHDr->nItemNo != NONE_SELECTED)
	{
		if(pListNMHDr->bChecked)
		{
			//MessageBox("Checked");
		}
		else
		{
			//MessageBox("UnChecked");
		}
	}
}
void CGameListView::OnHTMLList_SelectionChanged(NMHDR* pNMHDR, LRESULT*)
{
	NM_HTMLLISTCTRL *pListNMHDr = (NM_HTMLLISTCTRL*) pNMHDR;


	if(pListNMHDr->nItemNo != NONE_SELECTED)
	{
		//MessageBox(pListNMHDr->sItemText);
	}
	
}
void CGameListView::OnSize(UINT nType, int cx, int cy)
{
	CWnd::OnSize(nType, cx, cy);
	//was only testing the resizing
	if(IsWindow(m_list.GetSafeHwnd()))
	{
		CRect rc;
		m_list.GetClientRect(&rc);
		rc.right = cx;
		rc.bottom = cy;
		m_list.MoveWindow(&rc);
	}
	// TODO: Add your message handler code here
}

void CGameListView::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
	//__super::OnActivate(nState, pWndOther, bMinimized);

	// TODO: Add your message handler code here
}

